package com.nytimes.ohos.store.sample;

import com.nytimes.ohos.external.store3.base.impl.BarCode;
import com.nytimes.ohos.external.store3.base.impl.Store;
import com.nytimes.ohos.external.store3.base.impl.StoreBuilder;
import io.reactivex.Single;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import org.junit.Before;
import org.junit.Test;


import static org.junit.Assert.assertEquals;

public class ExampleOhosTest {
    private Store<String, BarCode> testStore;
    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.nytimes.ohos.store.sample", actualBundleName);
    }


    @Before
    public void setUp() throws Exception {
        testStore = StoreBuilder.<String>barcode()
                .fetcher(barCode -> Single.just("hello"))
                .open();
    }

    @Test
    public void testRepeatedGet() throws Exception {
        String first = testStore.get(BarCode.empty()).blockingGet();
        assertEquals(first, "hello");
    }
}
